package cn.edu.tsinghua.cs.jwh;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class PlacesOverlay extends ItemizedOverlay {
	
	private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();  
	private Context context;
	
	public PlacesOverlay(Drawable defaultMarker) {
		super(defaultMarker);
		// TODO Auto-generated constructor stub
		
	}
	
	public PlacesOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		this.context = context;
	}

	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return mapOverlays.get(i);
	}


	@Override
	public int size() {
		// TODO Auto-generated method stub
		return mapOverlays.size();
	}
	
	
	@Override
    protected boolean onTap(int index) {
	    OverlayItem item = mapOverlays.get(index);
	    AlertDialog.Builder dialog = new AlertDialog.Builder(context);
	    dialog.setTitle(item.getTitle());
	    dialog.setMessage(item.getSnippet());
	    dialog.show();
	    return true;
    }
	    
	public void addOverlay(OverlayItem overlay) {
	    mapOverlays.add(overlay);
	    this.populate();
	}

}
